package com.zzyl.serve.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
import com.zzyl.serve.domain.Device;
import org.apache.ibatis.annotations.Select;

/**
 * 设备信息Mapper接口
 * 
 * @author ruoyi
 * @date 2025-05-10
 */
@Mapper
public interface DeviceMapper extends BaseMapper<Device>
{
    /**
     * 查询设备信息
     * 
     * @param id 设备信息主键
     * @return 设备信息
     */
    public Device selectDeviceById(Long id);

    /**
     * 查询设备信息列表
     * 
     * @param device 设备信息
     * @return 设备信息集合
     */
    public List<Device> selectDeviceList(Device device);

    /**
     * 新增设备信息
     * 
     * @param device 设备信息
     * @return 结果
     */
    public int insertDevice(Device device);

    /**
     * 修改设备信息
     * 
     * @param device 设备信息
     * @return 结果
     */
    public int updateDevice(Device device);

    /**
     * 删除设备信息
     * 
     * @param id 设备信息主键
     * @return 结果
     */
    public int deleteDeviceById(Long id);

    /**
     * 批量删除设备信息
     * 
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteDeviceByIds(Long[] ids);
    /**
     * 根据老人随身设备的ID查询护理人员id
     * @param iotId
     * @return
     */
    @Select("select su.user_id from sys_user su\n" +
            "    left join nursing_elder ne on su.user_id = ne.nursing_id\n" +
            "    left join elder e on e.id = ne.elder_id\n" +
            "    left join device d on d.binding_location = e.id and d.location_type = 0\n" +
            "where d.iot_id = #{iotId}")
    List<Long> selectNursingIdsByIotIdWithElder(String iotId);
    /**
     * 根据床位等固定设备的ID查询护理人员的ID 为什么这个是护理
     * 因为床位有心率检测，那个维修人员的是烟雾报警器or温度之类的
     * @param iotId
     * @return
     */
    @Select("select su.user_id from sys_user su\n" +
            "    left join nursing_elder ne on su.user_id = ne.nursing_id\n" +
            "    left join elder e on e.id = ne.elder_id\n" +
            "    left join bed b on b.id = e.bed_id\n" +
            "    left join device d on d.binding_location = b.id and d.location_type = 1 and d.physical_location_type = 2\n" +
            "where d.iot_id = #{iotId}")
    List<Long> selectNursingIdsByIotIdWithBed(String iotId);
}
